package io.renren.modules.sys.controller;

import java.util.Arrays;
import java.util.List;
import java.util.Map;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import io.renren.modules.sys.entity.DictDataManagerEntity;
import io.renren.modules.sys.service.DictDataManagerService;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.R;



/**
 *
 *
 * @author hlw
 * @email sunlightcs@gmail.com
 * @date 2023-12-08 10:07:17
 */
@RestController
@RequestMapping("sys/dictdatamanager")
public class DictDataManagerController {
    @Autowired
    private DictDataManagerService dictDataManagerService;

    /**
     * 列表
     */
 /*   @RequestMapping("/list")
    @RequiresPermissions("sys:dictdatamanager:list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = dictDataManagerService.queryPage(params);

        return R.ok().put("page", page);
    }
*/
    /**
     * 列表
     */
    @RequestMapping("/list")
    @RequiresPermissions("sys:dictdatamanager:list")
    public R list(@RequestParam String dictCode){
        QueryWrapper queryWrapper = new QueryWrapper();
        queryWrapper.eq("dict_code",dictCode);
        List<DictDataManagerEntity> data  = dictDataManagerService.list(queryWrapper);

        return R.ok().put("data", data);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    @RequiresPermissions("sys:dictdatamanager:info")
    public R info(@PathVariable("id") Long id){
		DictDataManagerEntity dictDataManager = dictDataManagerService.getById(id);

        return R.ok().put("dictDataManager", dictDataManager);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    @RequiresPermissions("sys:dictdatamanager:save")
    public R save(@RequestBody DictDataManagerEntity dictDataManager){
		dictDataManagerService.save(dictDataManager);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @RequiresPermissions("sys:dictdatamanager:update")
    public R update(@RequestBody DictDataManagerEntity dictDataManager){
		dictDataManagerService.updateById(dictDataManager);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    @RequiresPermissions("sys:dictdatamanager:delete")
    public R delete(@RequestBody Long[] ids){
		dictDataManagerService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }
    /**
     * 根据code值获取全部的字典data
     */
    @RequestMapping("/getAllListByCode")
    public R getAllListByCode(@RequestParam String code){
        List<DictDataManagerEntity> allListByCode = dictDataManagerService.getAllListByCode(code);
        return R.ok().put("data",allListByCode);
    }

}
